import request from '@/utils/request'

// 获取文章列表
export function fetchArticles(params) {
  return request({
    url: '/articles/',
    method: 'get',
    params
  })
}

// 获取状态为draft的文章
export function fetchDraftArticles() {
  return request({
    url: '/articles/draft/',
    method: 'get'
  })
}

// 获取状态为published的文章
export function fetchPublishedArticles() {
  return request({
    url: '/articles/published/',
    method: 'get'
  })
}

// 获取单篇文章
export function fetchArticle(id) {
  return request({
    url: `/articles/${id}`,
    method: 'get'
  })
}

// 创建文章
export function createArticle(data) {
  return request({
    url: '/articles/',
    method: 'post',
    data
  })
}

// 更新文章
export function updateArticle(id, data) {
  return request({
    url: `/articles/${id}`,
    method: 'put',
    data
  })
}

// 删除文章
export function deleteArticle(id) {
  return request({
    url: `/articles/${id}`,
    method: 'delete'
  })
}
